package com.lipi.mall.product.web;

import com.lipi.mall.product.entity.CategoryEntity;
import com.lipi.mall.product.service.CategoryService;
import com.lipi.mall.product.vo.Catelog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.ws.rs.GET;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    /**
     * 视图解析器默认拼串规则
     * classpath:/templates/ +返回值+ .html
     *
     * @return
     */

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/", "/index.html"})
    public String indexPage(Model model) {

        // 查询出一级分类数据
        List<CategoryEntity> categoryEntityList = categoryService.getCateorysLevel1();
        model.addAttribute("categorys", categoryEntityList);

        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catelog2VO>> getCatalogJson() {
        Map<String, List<Catelog2VO>> map = categoryService.getCatalogJson();
        return map;
    }
}
